<template>
  <div class="ai-features-page">
    <!-- 顶部导航 -->
    <van-nav-bar
      title="伴伴AI助手"
      left-text="返回"
      left-arrow
      @click-left="$router.go(-1)"
      class="custom-nav-bar"
    />

    <!-- 欢迎横幅 -->
    <div class="welcome-banner">
      <div class="banner-content">
        <div class="welcome-text">
          <h2>你好，{{ displayUserName }}同学！</h2>
          <p>我是你的伴伴AI助手，随时为你服务</p>
        </div>
        <div class="welcome-avatar">🤖</div>
      </div>

    </div>

    <!-- 特色功能区域 -->
    <div class="featured-section">
      <!-- 语音通话特色功能 -->
      <div class="voice-call-section">
        <div class="voice-call-banner" @click="navigateToVoiceCall">
          <div class="voice-call-content">
            <div class="voice-call-icon">📞</div>
            <div class="voice-call-info">
              <h2 class="voice-call-title">🎙️ 语音通话</h2>
              <p class="voice-call-desc">实时语音对话，如同面对面交流</p>
              <div class="voice-call-features">
                <span class="feature-tag">实时对话</span>
                <span class="feature-tag">智能助手</span>
                <span class="feature-tag">多语言</span>
              </div>
            </div>
            <div class="voice-call-action">
              <div class="start-button">开始通话</div>
              <div class="hot-badge">🔥 HOT</div>
            </div>
          </div>
        </div>
      </div>

      <!-- 数字人通话特色功能 -->
      <div class="digital-human-section">
        <div class="digital-human-banner" @click="navigateToDigitalHuman">
          <div class="digital-human-content">
            <div class="digital-human-icon">🤖</div>
            <div class="digital-human-info">
              <h2 class="digital-human-title">👤 数字人通话</h2>
              <p class="digital-human-desc">与伴伴AI数字人面对面交流，更真实的体验</p>
              <div class="digital-human-features">
                <span class="feature-tag">视频通话</span>
                <span class="feature-tag">数字人</span>
                <span class="feature-tag">智能交互</span>
              </div>
            </div>
            <div class="digital-human-action">
              <div class="start-button">开始对话</div>
              <div class="new-badge">✨ NEW</div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 功能网格 -->
    <div class="features-container">
      <h3 class="section-title">AI功能大全 ({{ otherFeatures.length }}个功能)</h3>
      <div class="features-grid">
        <div
          v-for="feature in otherFeatures"
          :key="feature.id"
          class="feature-card"
          @click="navigateToFeature(feature)"
        >
          <div class="feature-header">
            <div class="feature-icon">{{ feature.icon }}</div>
            <div class="feature-badge" v-if="feature.isNew">NEW</div>
            <div class="feature-badge hot-badge" v-if="feature.id === 'voice-call'">🔥 HOT</div>
          </div>
          <div class="feature-content">
            <h4 class="feature-title">{{ feature.title }}</h4>
            <p class="feature-desc">{{ feature.description }}</p>
          </div>
          <div class="feature-arrow">
            <van-icon name="arrow" />
          </div>
        </div>
      </div>
    </div>






  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { showToast } from 'vant'
import { getUserInfo } from '@/utils/auth'

const router = useRouter()
// 用户信息
const userInfo = computed(() => getUserInfo())

// 显示用户名（如果没有用户名或为默认值，则显示"小明"）
const displayUserName = computed(() => {
  const user = userInfo.value
  if (!user || !user.username || user.username === '用户') {
    return '小明'
  }
  return user.username
})

// 功能列表 - 根据需求定制，为每个功能添加选项
const allFeatures = ref([
  {
    id: 'voice-call',
    title: '🎙️ 语音通话',
    description: '实时语音对话，如同面对面交流',
    icon: '📞',
    route: '/voice-call',
    isNew: true,
    options: ['实时语音对话', '智能语音助手', '多语言支持', '情感识别', '自然交流']
  },
  {
    id: 'knowledge-qa',
    title: '知识问答',
    description: '知识渊博的AI助手，回答各种问题',
    icon: '🧠',
    route: '/ai-features/knowledge-qa',
    isNew: false,
    options: ['百科知识', '科学技术', '历史文化', '生活常识', '学术研究']
  },
  {
    id: 'information-query',
    title: '信息查询',
    description: '查询天气、电话等各类信息',
    icon: '🔍',
    route: '/ai-features/information-query',
    isNew: false,
    options: ['天气查询', '股票行情', '新闻资讯', '交通信息', '汇率查询']
  },
  {
    id: 'text-generation',
    title: '文本生成',
    description: '写作文、故事、诗歌等创意内容',
    icon: '✍️',
    route: '/ai-features/text-generation',
    isNew: false,
    options: ['创意写作', '商务文案', '学术论文', '诗歌创作', '故事续写']
  },
  {
    id: 'translation',
    title: '语言翻译',
    description: '多语言即时翻译，准确流畅',
    icon: '🌐',
    route: '/ai-features/translation',
    isNew: false,
    options: ['中英互译', '多语种翻译', '文档翻译', '口语翻译', '专业术语']
  },
  {
    id: 'emotional-companion',
    title: '情感陪伴',
    description: '情感识别与温暖回应',
    icon: '💝',
    route: '/ai-features/emotional-companion',
    isNew: false,
    options: ['心理疏导', '情感倾诉', '压力缓解', '正能量激励', '冥想引导']
  },
  {
    id: 'recommendation',
    title: '智能推荐',
    description: '个性化内容推荐服务',
    icon: '🎯',
    route: '/ai-features/recommendation',
    isNew: false,
    options: ['音乐推荐', '书籍推荐', '电影推荐', '美食推荐', '旅游推荐']
  },
  {
    id: 'game-entertainment',
    title: '游戏娱乐',
    description: '语音游戏互动，寓教于乐',
    icon: '🎮',
    route: '/ai-features/game-entertainment',
    isNew: false,
    options: ['猜谜游戏', '成语接龙', '知识竞答', '故事接龙', '脑筋急转弯']
  },
  {
    id: 'health-management',
    title: '健康管理',
    description: '健康数据分析与建议',
    icon: '🏥',
    route: '/ai-features/health-management',
    isNew: false,
    options: ['运动计划', '饮食建议', '睡眠分析', '健康评估', '养生指导']
  },
  {
    id: 'image-generation',
    title: 'AI文生图',
    description: '文字描述生成精美图片',
    icon: '🎨',
    route: '/ai-features/image-generation',
    isNew: true,
    options: null // 文生图不添加选项
  }
])

// 分离语音通话和其他功能
const otherFeatures = computed(() => {
  return allFeatures.value.filter(feature => feature.id !== 'voice-call')
})

const features = computed(() => {
  return allFeatures.value
})



// 语音通话专用导航方法
const navigateToVoiceCall = () => {
  navigateToFeature({ id: 'voice-call', route: '/voice-call' })
}

// 数字人通话专用导航方法
const navigateToDigitalHuman = () => {
  navigateToFeature({ id: 'digital-human', route: '/digital-human' })
}

// 导航到功能页面
const navigateToFeature = (feature: any) => {
  if (feature.id === 'voice-call') {
    // 语音通话特殊处理：显示分阶段的加载效果
    showToast({
      type: 'loading',
      message: '正在初始化语音引擎...',
      duration: 0,
      forbidClick: true
    })

    // 第一阶段：初始化语音引擎
    setTimeout(() => {
      showToast({
        type: 'loading',
        message: '正在连接AI语音服务...',
        duration: 0,
        forbidClick: true
      })
    }, 1000)

    // 第二阶段：连接服务
    setTimeout(() => {
      showToast({
        type: 'loading',
        message: '正在准备通话环境...',
        duration: 0,
        forbidClick: true
      })
    }, 2000)

    // 第三阶段：准备完成
    setTimeout(() => {
      showToast({
        type: 'success',
        message: '🎙️ 语音通话已准备就绪！',
        duration: 1200
      })

      setTimeout(() => {
        router.push(feature.route)
      }, 1200)
    }, 3000) // 3秒总加载时间
  } else {
    // 其他功能的正常加载
    showToast({
      type: 'loading',
      message: '正在加载...',
      duration: 800
    })

    setTimeout(() => {
      router.push(feature.route)
    }, 800)
  }
}





onMounted(() => {
  // 页面初始化逻辑（如果需要的话）
})
</script>

<style scoped>
.ai-features-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding-bottom: 20px;
}

.custom-nav-bar {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.welcome-banner {
  margin: 20px 16px;
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.banner-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.welcome-text h2 {
  font-size: 24px;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 8px 0;
}

.welcome-text p {
  font-size: 14px;
  color: #64748b;
  margin: 0;
}

.welcome-avatar {
  font-size: 48px;
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-10px); }
  60% { transform: translateY(-5px); }
}



.features-container {
  padding: 0 16px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: #1e293b;
  margin: 20px 0 16px 0;
}

.features-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 32px;
}

/* iPad适配 */
@media (min-width: 768px) {
  .ai-features-page {
    padding: 0 40px 40px;
  }

  .welcome-banner {
    margin: 30px 0;
    padding: 32px;
  }

  .features-container {
    padding: 0;
  }

  .features-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }

  .section-title {
    font-size: 20px;
    margin: 30px 0 20px 0;
  }
}

.feature-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.feature-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border-color: #3b82f6;
}

.feature-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.feature-icon {
  font-size: 28px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.feature-badge {
  background: #ef4444;
  color: white;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 500;
}

.hot-badge {
  background: linear-gradient(45deg, #ff9500, #ff6b00);
  animation: pulse 2s infinite;
  margin-left: 4px;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.8;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.feature-content {
  margin-bottom: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.feature-title {
  font-size: 16px;
  font-weight: 600;
  color: #1e293b;
  margin: 0 0 8px 0;
}

.feature-desc {
  font-size: 13px;
  color: #64748b;
  margin: 0 0 12px 0;
  line-height: 1.4;
}



.feature-arrow {
  color: #94a3b8;
  font-size: 14px;
}



.voice-call-card:active::after {
  width: 300px;
  height: 300px;
}

/* 特色功能区域样式 */
.featured-section {
  margin-bottom: 24px;
}

/* 语音通话横幅样式 */
.voice-call-section {
  margin-bottom: 16px;
}

/* 数字人通话横幅样式 */
.digital-human-section {
  margin-bottom: 24px;
}

.voice-call-banner {
  width: 100%;
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #fecfef 100%);
  border-radius: 16px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(255, 154, 158, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
}

.voice-call-banner:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(255, 154, 158, 0.3);
}

.voice-call-banner::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transform: rotate(45deg);
  animation: shimmer 4s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%) translateY(-100%) rotate(45deg);
  }
  100% {
    transform: translateX(100%) translateY(100%) rotate(45deg);
  }
}

.voice-call-banner:active {
  transform: translateY(0);
}

.voice-call-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

.voice-call-icon {
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  animation: pulse-icon 3s infinite;
}

@keyframes pulse-icon {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(255, 255, 255, 0);
  }
}

.voice-call-info {
  flex: 1;
}

.voice-call-title {
  color: #2c3e50;
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px 0;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
}

.voice-call-desc {
  color: #34495e;
  font-size: 14px;
  margin: 0 0 12px 0;
  opacity: 0.8;
}

.voice-call-features {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.feature-tag {
  background: rgba(255, 255, 255, 0.3);
  color: #2c3e50;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  font-weight: 500;
}

.voice-call-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.start-button {
  background: rgba(255, 255, 255, 0.9);
  color: #e74c3c;
  padding: 12px 20px;
  border-radius: 25px;
  font-weight: 600;
  font-size: 14px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  transition: all 0.3s ease;
  box-shadow: 0 2px 10px rgba(231, 76, 60, 0.2);
}

.start-button:hover {
  background: white;
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.voice-call-action .hot-badge {
  background: linear-gradient(45deg, #ff9500, #ff6b00);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: bold;
  animation: pulse 2s infinite;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .voice-call-content {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }

  .voice-call-action {
    flex-direction: row;
    justify-content: center;
  }

  .voice-call-title {
    font-size: 18px;
  }
}

/* 数字人通话横幅样式 */
.digital-human-banner {
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 16px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
}

.digital-human-banner:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(102, 126, 234, 0.3);
}

.digital-human-banner::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transform: rotate(45deg);
  animation: shimmer 4s infinite;
}

.digital-human-banner:active {
  transform: translateY(0);
}

.digital-human-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

.digital-human-icon {
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  animation: pulse-icon 3s infinite;
}

.digital-human-info {
  flex: 1;
}

.digital-human-title {
  color: white;
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.digital-human-desc {
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  margin: 0 0 12px 0;
  opacity: 0.9;
}

.digital-human-features {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.digital-human-features .feature-tag {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.digital-human-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.digital-human-action .start-button {
  background: rgba(255, 255, 255, 0.9);
  color: #667eea;
  box-shadow: 0 2px 10px rgba(255, 255, 255, 0.2);
}

.digital-human-action .start-button:hover {
  background: white;
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(255, 255, 255, 0.3);
}

.digital-human-action .new-badge {
  background: linear-gradient(45deg, #4CAF50, #45a049);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: bold;
  animation: pulse 2s infinite;
}

/* 数字人响应式设计 */
@media (max-width: 768px) {
  .digital-human-content {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }

  .digital-human-action {
    flex-direction: row;
    justify-content: center;
  }

  .digital-human-title {
    font-size: 18px;
  }
}



</style>
